home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / Tape Stuff / FullFileName.c < prev    next >
Encoding:
Text File  |  1992-11-21  |  1.6 KB  |  58 lines  |  [TEXT/KAHL]

  1. short FullFileName(StringPtr outname, StringPtr tail, short volume, long dirID);
  2.  
  3. short FullFileName(StringPtr outname, StringPtr tail, short volume, long dirID)
  4. {    StringHandle name; Str255 text, volname; HVolumeParam hvp;
  5.     CInfoPBRec di; long size; short err;
  6.  
  7.     /* extract the volume name */
  8.     hvp.ioNamePtr = volname;
  9.     hvp.ioVRefNum = volume;
  10.     hvp.ioVolIndex = 0;
  11.     PBHGetVInfo((HParmBlkPtr)&hvp, false);
  12.     if (hvp.ioVSigWord == 0xd2d7) { outname[0] = 0; return wrgVolTypErr; }
  13.  
  14.     /* create and initialize the name handle */
  15.     if (tail) {
  16.         if (err = PtrToHand(tail + 1, &name, tail[0])) return err;
  17.         size = tail[0];
  18.     }
  19.     else {    if ((name = (StringHandle)NewHandle(0)) == 0) return MemError();
  20.         size = 0;
  21.     }
  22.  
  23.     /* now start extracting the dirs and prepending them to
  24.      * the handle
  25.      */
  26.     for ( ; dirID != 2; dirID = di.dirInfo.ioDrParID) {
  27.         text[0] = 0;
  28.         di.dirInfo.ioNamePtr = text;
  29.         di.dirInfo.ioVRefNum = volume;
  30.         di.dirInfo.ioFDirIndex = -1;
  31.         di.dirInfo.ioDrDirID = dirID;
  32.         PBGetCatInfo(&di, false);
  33.         text[++text[0]] = ':';
  34.         SetHandleSize(name, size += text[0]);
  35.         BlockMove((Ptr)*name, (Ptr)(*name) + text[0], size - text[0]);
  36.         BlockMove((Ptr)text + 1, (Ptr)*name, text[0]);
  37.     }
  38.  
  39.     /* prepend the volume name onto the handle */
  40.     volname[++volname[0]] = ':';
  41.     SetHandleSize(name, size += volname[0]);
  42.     BlockMove((Ptr)*name, (Ptr)(*name) + volname[0], size - volname[0]);
  43.     BlockMove((Ptr)volname + 1, (Ptr)*name, volname[0]);
  44.  
  45.     /* copy and delete the handle */
  46.     if (size > 255) {
  47.         DisposHandle(name);
  48.         SysBeep(12);
  49.         outname[0] = 0;
  50.         return bdNamErr;
  51.     }
  52.     outname[0] = size;
  53.     BlockMove((Ptr)*name, (Ptr)outname + 1, size);
  54.     DisposHandle(name);
  55.     return noErr;
  56. }
  57.  
  58.